package com.ebrothers.isns.controller;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;

public abstract class ViewController {

	private Context mContext;
	private View mContentView;
	private Bundle mData;
	private Handler mHandler;

	public ViewController(Context context, View view) {
		mContext = context;
		mContentView = view;
		mHandler = new Handler();
	}

	public abstract void onViewBinded(View view);

	public abstract void onViewSelected(Bundle data);

	public void onViewUnselected() {

	}

	public void onResume() {

	}

	public void onPause() {

	}

	public void onDestroy() {

	}

	public View getContentView() {
		return mContentView;
	}

	public Context getContext() {
		return mContext;
	}

	public boolean isBinded() {
		return mContentView != null;
	}

	public void setData(Bundle data) {
		mData = data;
	}

	public Bundle getData() {
		return mData;
	}

	public void requestRefresh() {
		mHandler.post(new Runnable() {
			public void run() {
				onViewSelected(getData());
			}
		});
	}
}
